<cpanel include="./config.php">
<?

/***************************************************************************
 *                              preferences.php
 *                            -------------------
 *   Begin                : Monday, May 16, 2005
 *   Copyright            : (C) 2005 Point and Code
 *   Domain               : http://www.pointandcode.com/
 *   Email                : support@pointandcode.com
 *   Version              : 1.0.1
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

// Set some variables
$html_root_path = './';

// Include some pages
include $root_path.'common.php';
$page_title = $lang['preferences'];
include $root_path.'page_header.php';

$template->set_filenames(array(
	'body' => $root_path.$template_path.'preferences_body.tpl')
);





//
// Checks for a submit
//

if (!empty($_REQUEST['submit'])) {

$path_to_home = <<<EOFpacman
<cpanel print="$homedir">
EOFpacman;

	$filename = $path_to_home . '/.cpzen';

	if (!$handle = fopen($filename, 'w')) {
		message_die( "Cannot open file ($filename)" );
	}
	
	$content = $_REQUEST['template'] . "\n" . $_REQUEST['language'];
	
	fwrite($handle, $content);
	
	fclose($handle);
	
	message_die( 'Your preferences have been recorded. Changes will take effect immediately upon leaving this page.' );
	

}



//
// Create popup menus
//

$handle = opendir($root_path.'templates/');

$installed_templates = array();

while (false !== ($file = readdir($handle))) { 
	if ($file != '.' and $file != '..') {
		array_push($installed_templates, $file);
	}
}

foreach ($installed_templates as $row) {

	if ($row == $config['template']) {
		$selected = 'selected';
	} else {
		$selected = '';
	}

	$template->assign_block_vars('templaterow', array(
		'NAME' => $row,
		'SELECTED' => $selected
		)
	);
}




//
// And language
//

$handle = opendir($root_path.'language/');

$installed_languages = array();

while (false !== ($file = readdir($handle))) { 
	if ($file != '.' and $file != '..') {
		array_push($installed_languages, substr($file, 0, -4));
	}
}

foreach ($installed_languages as $row) {

	$template->assign_block_vars('languagerow', array(
		'NAME' => $row
		)
	);
}






$template->pparse('body');


?>

<cpanel include="./page_tail.php">